package com.chouren.goandroid.animate.effect;

import android.view.View;

import com.nineoldandroids.animation.AnimatorSet;
import com.nineoldandroids.view.ViewHelper;

public abstract class BaseEffect {
	protected long duration;
	protected long startDelay;
	private AnimatorSet animatorSet;
	
	public BaseEffect() {
		animatorSet = new AnimatorSet();
	}
	
	public void start(View view) {
		reset(view);
		setAnimators(view);
		animatorSet.start();
	}
	
	protected void reset(View view) {
		ViewHelper.setPivotX(view, view.getMeasuredWidth() / 2);
		ViewHelper.setPivotY(view, view.getMeasuredHeight() / 2);
	}
	
	protected abstract void setAnimators(View view);

	public BaseEffect setDuration(long duration) {
		this.duration = duration;
		animatorSet.setDuration(duration);
		return this;
	}
	
	public BaseEffect setStartDelay(long startDelay) {
		this.startDelay = startDelay;
		animatorSet.setStartDelay(startDelay);
		return this;
	}
	
	protected AnimatorSet getAnimatorSet() {
		return animatorSet;
	}
}
